<template>
  <el-menu
    default-active="2"
    class="el-menu-vertical-demo"
    background-color="#545c64"
    text-color="#fff"
    active-text-color="#ffd04b"
    :unique-opened="true"
    :collapse="isCollese"
  >
    <el-menu-item
      :index="item.path"
      v-for="item in noChildren"
      :key="item.path"
      @click="handleMeum(item)"
    >
      <i :class="'el-icon-' + item.icon"></i>
      <span slot="title">{{ item.label }}</span>
    </el-menu-item>

    <el-submenu index="1" v-for="(item, index) in hasChildren" :key="index">
      <template slot="title">
        <i :class="'el-icon-' + item.icon"></i>
        <span>{{ item.label }}</span>
      </template>
      <el-menu-item-group>
        <el-menu-item
          :index="subItem.path"
          v-for="subItem in item.children"
          :key="subItem.path"
          @click="handleMeum(subItem)"
        >
          <i :class="'el-icon-' + subItem.icon"></i>
          {{ subItem.label }}
        </el-menu-item>
      </el-menu-item-group>
    </el-submenu>
  </el-menu>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  data() {
    return {
      asideData: [
        {
          path: '/',
          label: '首页',
          icon: 's-home',
        },
        {
          path: '/user',
          label: '用户管理',
          icon: 'user',
        },
        {
          path: '/video',
          label: '视频',
          icon: 'video-play',
        },
        {
          label: '其它',
          icon: 'menu',
          children: [
            {
              path: '/other',
              label: '爱好',
              icon: 's-fold',
            },
            {
              path: '/other2',
              label: '爱好2',
              icon: 's-open',
            },
          ],
        },
      ],
    }
  },
  computed: {
    noChildren() {
      return this.asideData.filter((item) => !item.children)
    },
    hasChildren() {
      return this.asideData.filter((item) => item.children)
    },
    ...mapGetters(['isCollese']),
  },
  created() {
    console.log(this.isCollese)
  },
  methods: {
    handleMeum(item) {
      // 选中菜单
      this.$router.push({ path: item.path })
      this.$store.commit('asideMeum/selectMeum', item)
    },
  },
}
</script>

<style lang="scss" scoped>
.el-menu {
  height: 100%;
  border: none;
}
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
</style>
